const express = require('express');
const appconfig = require('./config/appconfig');
const  path = require("path");
const connect = require('./model/mysql');
const    app  =express()
const router = require('./router/userlogin')
const session = require('express-session');
const authentication = require('./Middleware/authentication');
app.use(express.json()) // for parsing application/json
app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded
app.engine('html', require('express-art-template'));
app.use("/static" , express.static('./static'))

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'html');

//  模板引擎:   先读取文件 fs.readfile  进行匹配 识别 ({{  (asdasd)  }})  得到asdasd 然后去找我们传递的数据  
//      obj =  {  user:"谢梓楠"}    obj[asdasd] ?  repleace   替换  这个才真正变成 html

app.use(session({ 
    // 产生session
    secret: '!@#!@#$@#$%!@!@12',
    cookie:{ 
        maxAge :72000
    }
// 
}))
// 
// 对 上面产生session进行校验
app.use(authentication)

app.use(router)

app.get("/get",(req,res)=>{
    var sql = `select * from user `
    connect(sql).then( res =>{
        console.log(res);
    })
        res.json( { 
             code:20000,
             msg:"success"
        })
})

app.post("/post",(req,res)=>{
    console.log( req.body  );
    let {  uuid  } = req.body
    console.log( "uuid",uuid);
        res.json( { 
             code:20000,
             msg:"successpost"
        })
})



app.listen(appconfig.port , ()=>{
    console.log("服务端口"+appconfig.port);
})